function trimTA(id_ta,id_co,maxLen){
	var ta=$(id_ta);
	var counter=$(id_co);

	var updCounter = function (el_ta,el_co,maxLen){
		var available=(maxLen - el_ta.value.length >=0) ? maxLen - el_ta.value.length : 0;
		el_co.setText(available);
		if(available == 0){
			 el_ta.value=el_ta.value.substr(0,maxLen);
			 
		}
	}
	 
	ta.addEvents({
		'focus': function() {
			updCounter(this,counter,maxLen);
		},
		'blur': function() {
			updCounter(this,counter,maxLen);
		},
		'keyup': function() {
			updCounter(this,counter,maxLen);
		},
		'click': function() {
			updCounter(this,counter,maxLen);
		}
	});
	
	updCounter(ta,counter,maxLen);
}

function addEventsSender(id_f,id_t,id_l,id_log,id_co,maxLen){
	var f=$(id_f);
	var t=$(id_t);
	var l=$(id_l);
	var log=$(id_log);
	var counter=$(id_co);
	
	l.addEvent('click',function(){
		if(t.value!=''){
			log.empty().addClass('ajax-loading');
			f.send({
				method:'post',
				onFailure: function() {
				    new Ajax('/list_sms_ajax',{
						method:'get',
						update:log,
						onComplete:function(){
							log.removeClass('ajax-loading');							
						}
					}).request();
					t.value='';
					counter.setText(maxLen);
                    
				},
				onComplete: function() {
					new Ajax('/list_sms_ajax',{
						method:'get',
						update:log,
						onComplete:function(){
							log.removeClass('ajax-loading');							
						}
					}).request();
					t.value='';
					counter.setText(maxLen);
				}
			});
			
		}
		else{
			alert('El mensaje para mamá está vacío, mejor no lo enviamos...');
		}		
	});
}


function addEventsCopi(id_f,id_l,id_log,c_log,c_pass){
    var f=$(id_f);
    var t=$(c_log);
    var p=$(c_pass);
	var l=$(id_l);
	var log=$(id_log);
	
	l.addEvent('click',function(){
		if(t.value!='' && p.value!=''){			
			log.empty().addClass('ajax-loading');
		    new Ajax('/get_copiagenda',{
			    method:'post',
				update:log,
				evalScripts:true,
				data:'telcopiag='+t.value+'&passcopiag='+p.value+'&authenticity_token='+$("authenticity_token").value,
				onComplete:function(){
					log.removeClass('ajax-loading');
  					mySlide.slideIn();  					
				}
			}).request();
		}
		else{
			alert('Rellena tus datos de copiagenda.');
		}		
	});
}

